<template>
	<view class="content">
		<!-- <view class="top">
			收款二维码
		</view> -->
		<view class="con2">
			<u-row>
				<u-col :span="6" v-for="(item,index) in arr" :key="index">
					<view class="list">
						<view class="title">
							<image :src="item.logo" mode=""></image>
							<view class="name">
								{{item.name}}
							</view>
							<view class="text" @click="show=true" v-if="item.id==5">
								<image src="../static/c6.png" mode=""></image>
								查看示例
								<text>></text>
							</view>
						</view>
						<view class="down">
							<image :src="item.img"></image>
							<view class="up" @click="upload(item.id)">
								<image src="../static/collection_tb2.png" mode=""></image>
								<view class="name">
									点击上传
								</view>
							</view>
						</view>
					</view>
				</u-col>
			</u-row>
		</view>
		<u-keyboard mode="number" :dot-enabled="false" v-model="pay" :tooltip="false" @change="onChange"
			@backspace="onBackspace">
			<view>
				<view class="u-text-center">
					<view class="u-text-name">
						二级密码
					</view>
					<view class="u-text-text">
						您当前正在进行交易，为确保账户安全请输入二级 密码验证身份
					</view>
				</view>
				<view class="u-flex u-row-center">
					<u-message-input mode="box" :maxlength="6" :dot-fill="true" v-model="password"
						:disabled-keyboard="true"></u-message-input>
				</view>
				<view class="u-text-center u-padding-top-10 u-padding-bottom-20 tips"></view>
			</view>
		</u-keyboard>
		<u-popup :closeable="true" close-icon-pos="top-left" borderRadius="30" mode="bottom" v-model="show">
			<view class="popup">
				<view class="_view">
					<view class="title">
						银行卡信息示例
					</view>
				</view>
				<view class="cont">
					<image src="../static/a12.png" class="img"></image>
					<view class="text">
						<image src="../static/a11.png"></image>
						<view class="view">
							信息中需要含有<text>账户名称 、开户银行、具体支行、开户账号</text> 如果缺少信息会影响后续操作
						</view>
					</view>
				</view>
				<u-button @click="show=false" type="success" :ripple="true" class="button">我知道了</u-button>
				<view class="popup_top"></view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	var than;
	export default {
		data() {
			return {
				pay: false,
				show: false,
				arr: [{
					name: '微信收款码',
					img: '../static/d1.png',
					logo: '../static/c1.png',
					id: 1
				}, {
					name: '支付宝收款码',
					img: '../static/d2.png',
					logo: '../static/c2.png',
					id: 2
				}, {
					name: '云闪付码',
					img: '../static/d3.png',
					logo: '../static/c3.png',
					id: 3
				}, {
					name: '聚合收款码',
					img: '../static/d4.png',
					logo: '../static/c4.png',
					id: 4
				}, {
					name: '银行卡信息',
					img: '../static/d6.png',
					logo: '../static/c5.png',
					id: 5
				}],
				password: "",
				collection_array: [],
				picture_type: 0
			}
		},
		onLoad(option) {
			than = this;
			if (option.type) {
				than.type = parseInt(option.type)
			}
			than.seeCollectionPictures()
		},
		methods: {
			seeCollectionPictures() {
				than.post("api/center/seeCollectionPictures", null, function(data) {
					for (let i = 0; i < data.length; i++) {
						for (let j = 0; j < than.arr.length; j++) {
							if (data[i].picture_type == than.arr[j].id) {
								than.arr[j].img = than.img_pre + data[i].user_picture
							}
						}
					}
					than.collection_array = data;
				})
			},
			upload(id) {
				than.picture_type = id;
				than.uploadCodeIcon();
			},
			uploadCodeIcon() {
				if (than.collection_array.length > 0) {
					than.pay = true;
				} else {
					than.aadc();
				}
			},
			onChange(val) {
				if (this.password.length < 6) {
					this.password += val;
				}

				if (this.password.length >= 6) {
					than.aadc();
				}
			},
			aadc() {
				uni.chooseImage({
					count: 1,
					sizeType: ['compressed'],
					success: function(res) {
						uni.showLoading({
							title: '上传中'
						});
						than.uploadPost("api/image/uploadMultiple", res.tempFilePaths[0], "file", function(
							data) {
							than.post("api/user/uploadNewCodeIcon", {
								user_picture: data.url,
								picture_type: than.picture_type,
								password: than.password
							}, function(data) {
								than.toast(data)
								than.pay = false;
								than.password = "";
								than.seeCollectionPictures()
							})
							uni.hideLoading();
						})
					}
				});
			},
			onBackspace(e) {
				if (this.password.length > 0) {
					this.password = this.password.substring(0, this.password.length - 1);
				}
			}
		}
	}
</script>

<style lang="less">
	.popup {
		width: 100%;

		.popup_top {
			height: 30rpx;
		}

		._view {
			background: #FFFFFF;

			.title {
				height: 108rpx;
				line-height: 108rpx;
				text-align: center;
				border-bottom: 2rpx solid #F6F6F6;
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
			}
		}

		.cont {
			text-align: center;
			padding-top: 50rpx;
			.img {
				width: 474rpx;
				height: 309rpx;
			}

			.text {
				padding-left: 60rpx;
				margin: 40rpx 0;
				display: flex;

				image {
					width: 32rpx;
					height: 32rpx;
					margin-top: 5rpx;
					margin-right: 14rpx;
				}

				.view {
					width: 600rpx;
					text-align: center;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #666666;

					text {
						color: #0176FE;
					}
				}
			}
		}

		.button {
			border-radius: 40rpx;
			border: 0;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			width: 245rpx;
			height: 74rpx;
			background: #FB683D;
			border-radius: 20rpx;
		}
	}

	page {
		background-color: #FAFAFA;
	}

	.content {
		padding: 0rpx 36rpx;
	}

	.top {
		padding: 40rpx 0rpx;
		font-size: 36rpx;
		font-weight: bold;
		color: #333333;
	}

	.con2 {
		margin-top: 50rpx;
		width: 100%;

		.u-col-6:last-child {
			flex: 1 !important;

			.list {
				.title {
					justify-content: left;
					padding-left: 100rpx;
				}

				height:450rpx;
			}

			.down {
				width: 359rpx;
				height: 246rpx;
				margin: auto;
				text-align: center;
				position: relative;

				.up {

					image {
						margin-top: 70rpx;
						width: 61rpx;
						height: 61rpx;
					}


				}

			}
		}

		.list {
			margin-bottom: 21rpx;
			height: 546rpx;
			background: white;
			// border: 4rpx dashed #E6E6E6;
			border-radius: 20rpx;

			.title {
				display: flex;
				height: 132rpx;
				align-items: center;
				justify-content: center;

				image {
					width: 50rpx;
					height: 46rpx;
					margin-right: 15rpx;
				}

				.name {
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
				}

				.text {
					display: flex;
					align-items: center;
					margin-left: auto;
					margin-right: 38rpx;

					image {
						width: 27rpx;
						height: 27rpx;
					}

					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #F66337;

					text {
						margin-left: 10rpx;
					}
				}
			}


			.down {
				width: 264rpx;
				height: 359rpx;
				margin: auto;
				text-align: center;
				position: relative;

				image {
					width: 100%;
					height: 100%;
				}

				.up {
					position: absolute;
					z-index: 10;
					width: 100%;
					height: 100%;
					top: 0;

					image {
						margin-top: 100rpx;
						width: 61rpx;
						height: 61rpx;
					}

					.name {
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #3E3E3E;
						width: 100%;
					}
				}
			}
		}
	}

	.con {
		margin-top: 50rpx;
		height: 769rpx;
		background: #F8F8F8;
		border: 4rpx solid #E6E6E6;
		border-radius: 20rpx;
		padding: 100rpx 130rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
		}

		.up {
			position: absolute;
			left: 0;
			right: 0;
			bottom: 0;
			top: 0;
			width: 200rpx;
			height: 200rpx;
			margin: auto;
			display: flex;
			flex-direction: column;
			align-items: center;

			.img {
				width: 61rpx;
				height: 61rpx;
			}

			.text {
				font-size: 30rpx;
				font-weight: bold;
				color: #3E3E3E;
			}
		}
	}
</style>
